<template>
    <div class="nav">
        <a-button @click="tohome">首页</a-button>
        <!-- 循环渲染导航菜单 -->
        <a-dropdown v-for="item in navTestData" :key="item.id" trigger="hover">
            <a-button @click="handleNavClick(item.link)">{{ item.label }}<icon-down /></a-button>
            <template #content>
                <a-doption v-for="subItem in item.subMenu" :key="subItem.id" @click="handleNavClick(subItem.link)">
                    {{ subItem.label }}
                </a-doption>
            </template>
        </a-dropdown>
        <a-button @click="toYiaibookstore">爱思唯尔好书</a-button>
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router'
import axios from 'axios';
const router = useRouter();
const route = useRoute()
const navData = ref([]);

const navTestData =
    [
        {
            "id": 1,
            "label": "线下培训",
            "link": "/train",
            "subMenu": [
                {
                    "id": 11,
                    "label": "培训伙伴",
                    "link": "/train/partner"
                },
                {
                    "id": 12,
                    "label": "培训管理班信息",
                    "link": "/train/class"
                },

            ]
        },
        {
            "id": 2,
            "label": "线上培训",
            "link": "/online",
            "subMenu": [
            ]
        },
        {
            "id": 3,
            "label": "师资介绍",
            "link": "/teacher",
            "subMenu": [

            ]
        },
    ]

const handleNavClick = (link: string) => {
    window.open(link, '_blank', 'noopener noreferrer');
}

const tohome = () => {
    router.push('/');
}
const toYiaibookstore = () => {
    router.push('/yiaibookstore');
}

const fetchNavData = async () => {
    try {
        // 替换为实际的后端接口地址
        const response = await axios.get('YOUR_API_URL');
        navData.value = response.data;
    } catch (error) {
        console.error('Failed to fetch navigation data:', error);
    }
};

onMounted(() => {
    // fetchNavData();
})

</script>
<style scoped>
.nav {
    height: 40px;
    width: 80%;
    text-align: center;
}

.arco-btn-secondary[type='button'] {
    background-color: transparent;
    font-size: 16px;
    line-height: 40px;
    padding: 0 24px;
}

.arco-btn-secondary[type='button']:hover {
    background-color: transparent;
}

.arco-trigger-popup {
    min-width: 160px;
    padding: 5px 0;
    margin: 0;
    list-style: none;
    font-size: 14px;
    text-align: left;
    background-color: #fff;
    border: 1px solid #ccc;
    border: 1px solid rgba(0, 0, 0, .15);
    border-radius: 4px;
    -webkit-box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
    box-shadow: 0 6px 12px rgba(0, 0, 0, .175);
    background-clip: padding-box;
}

.arco-trigger-popup:hover {
    background: #3f3f3f;
}

@media (min-width: 1024px) {}
</style>
